package weaver.interfaces.shengxu.duss.action;

import com.alibaba.fastjson.JSONObject;
import com.weaver.general.BaseBean;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.interfaces.shengxu.duss.utils.U9Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

/**
 * @Title: ecology-idea
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2024-06-05
 * @Description: 采购物料付款申请单调用U9更新审批接口
 * @ModifyLog:
 **/
public class WeaCgwlfksqdlcAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        String requestid = requestInfo.getRequestid();
        String tablename = requestInfo.getRequestManager().getBillTableName();
        String src = requestInfo.getRequestManager().getSrc();
        writeLog(">>>>>WeaCgwlfksqdlcAction>>>>>requestid=" + requestid);
        try {
            RecordSet rs = new RecordSet();
            U9Util u9Util = new U9Util();
            rs.executeQuery("select upqkdh,sqrfbbm from " + tablename + " where requestid=?", requestid);
            rs.next();
            String upqkdh = Util.null2String(rs.getString("upqkdh"));
            String orgcode = Util.null2String(rs.getString("sqrfbbm"));
            JSONObject paramsJson = new JSONObject();
            String userCode = Util.null2String(getPropValue("u9", "userCode"));
            String entcode = Util.null2String(getPropValue("u9", "entcode"));
            //String orgcode = Util.null2String(getPropValue("u9", "orgcode"));
            JSONObject contextJson = new JSONObject();
            contextJson.put("UserCode", userCode);
            contextJson.put("OrgCode", orgcode);
            contextJson.put("EntCode", entcode);
            contextJson.put("CultureName", "zh-CN");
            paramsJson.put("context", contextJson);
            paramsJson.put("docNo", upqkdh);
            writeLog(">>>>>WeaCgwlfksqdlcAction>>>>>paramsJson=" + paramsJson);
            JSONObject resultJson = u9Util.AppovedFKD(paramsJson, requestid, src);
            writeLog(">>>>>WeaCgwlfksqdlcAction>>>>>resultJson=" + resultJson);
            String message = Util.null2String(resultJson.getString("message"));
            if ("success".equals(message)) {
                String data = Util.null2String(resultJson.getString("data"));
                JSONObject dataJson = JSONObject.parseObject(data);
                JSONObject dJson = dataJson.getJSONObject("d");
                String IsSuccess = Util.null2String(dJson.getString("IsSuccess"));
                String ErrorMsg = Util.null2String(dJson.getString("ErrorMsg"));
                if ("true".equals(IsSuccess)) {
                    return Action.SUCCESS;
                } else {
                    message = ErrorMsg;
                }
            }
            requestInfo.getRequestManager().setMessageid("111111");
            requestInfo.getRequestManager().setMessagecontent("调用U9系统接口返回:" + message);
            return Action.FAILURE_AND_CONTINUE;
        } catch (Exception e) {
            writeLog(">>>>>WeaCgwlfksqdlcAction>>>>>Exception=" + e);
            requestInfo.getRequestManager().setMessageid("111111");
            requestInfo.getRequestManager().setMessagecontent("Action接口处理异常,请联系管理员");
            return Action.FAILURE_AND_CONTINUE;
        }
    }

}